
var before_sleep_audio=document.getElementById("before_sleep_audio");
var before_sleep_playing = false;
var after_sleep_audio=document.getElementById("after_sleep_audio");
var after_sleep_playing = false;

function na_restore_img_src(name, nsdoc)
{
    var img = eval((navigator.appName.indexOf('Netscape', 0) != -1) ? nsdoc+'.'+name : 'document.all.'+name);
    if (name == '')
        return;
    if (img && img.altsrc) {
        img.src    = img.altsrc;
        img.altsrc = null;
    }
}

function na_preload_img()
{
    var img_list = na_preload_img.arguments;
    if (document.preloadlist == null)
        document.preloadlist = new Array();
    var top = document.preloadlist.length;
    for (var i=0; i < img_list.length-1; i++) {
        document.preloadlist[top+i] = new Image;
        document.preloadlist[top+i].src = img_list[i+1];
    }
}

function na_change_img_src(name, nsdoc, rpath, preload)
{
    var img = eval((navigator.appName.indexOf('Netscape', 0) != -1) ? nsdoc+'.'+name : 'document.all.'+name);
    if (name == '')
        return;
    if (img) {
        img.altsrc = img.src;
        img.src    = rpath;
    }
}

$(document).ready(function() {
    $("#before_sleep").click(function(){
        try{
            after_sleep_audio.pause();
            console.log("click before sleep ");
        }
        catch(error){
            console.log("not playing");
        }
        if(before_sleep_playing == false) {
            before_sleep_audio.play();
            before_sleep_playing = true;
        }
        else {
            before_sleep_audio.pause();
            before_sleep_playing = false;
        }
        $("#music_text").text("meditation music play~");
    });

    $("#after_sleep").click(function(){
        try{
            console.log("click after sleep");
            before_sleep_audio.pause();
        }
        catch(error){
            console.log("not playing");
        }

        if(after_sleep_playing == false) {
            after_sleep_audio.play();
            after_sleep_playing = true;
        }
        else {
            after_sleep_audio.pause();
            after_sleep_playing = false;
        }
        $("#music_text").text("diet music play~");
    })
});

